home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / examples / balls.c.bak < prev    next >
Text File  |  1997-12-26  |  3KB  |  182 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #include "hershey.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #ifndef PI
  13. #define PI 3.1415926535
  14. #endif
  15.  
  16. #ifndef TC
  17. #include <math.h>
  18. #else
  19. extern double    sin(), cos();
  20. #endif
  21.  
  22. #define RADIUS 10.0
  23. #define    SPHERE    1L
  24.  
  25. /* ---------------------------------------------------------------------
  26.  * Prototypes:
  27.  */
  28. void makesphere(void);                                 /* balls.c         */
  29. int main(void);                                        /* balls.c         */
  30.  
  31. /* --------------------------------------------------------------------- */
  32.  
  33. /*
  34.  * makesphere
  35.  *
  36.  *    make a sphere object
  37.  */
  38. void makesphere(void)
  39. {
  40.     float    r, z;
  41.     int    i, a;
  42.  
  43.     makeobj(SPHERE);
  44.  
  45.         /*
  46.          * create the latitudinal rings
  47.          */
  48.         for (i = 0; i < 1800; i += 200) {
  49.             pushmatrix();
  50.                 rotate(i, 'y');
  51.                 circ(0.0, 0.0, RADIUS);
  52.             popmatrix();
  53.         }
  54.         
  55.         /*
  56.          * create the longitudinal rings
  57.          */
  58.         pushmatrix();
  59.             rotate(900, 'x');
  60.             for (a = -900; a < 900; a += 200) {
  61.                 r = RADIUS * cos((double)a * PI / 180.0);
  62.                 z = RADIUS * sin((double)a * PI / 180.0);
  63.                 pushmatrix();
  64.                     translate(0.0, 0.0, -z);
  65.                     circ(0.0, 0.0, r);
  66.                 popmatrix();    
  67.             }
  68.         popmatrix();
  69.  
  70.     closeobj();
  71. }
  72.  
  73. /*
  74.  * a demonstration of objects
  75.  */
  76. int main(void)
  77. {
  78.     short    val;
  79.  
  80.     winopen("balls");
  81.     hfont("times.rb");
  82.  
  83.     unqdevice(INPUTCHANGE);
  84.     qdevice(KEYBD);
  85.  
  86.     /*
  87.      * set up our viewing transformation
  88.      */
  89.     perspective(900, 1.0, 0.001, 500.0);
  90.     lookat(13.0, 13.0, 8.0, 0.0, 0.0, 0.0, 0);
  91.  
  92.     color(BLACK);
  93.     clear();
  94.  
  95.     /*
  96.      * Call a routine to make the sphere object
  97.      */
  98.     makesphere();
  99.  
  100.     /*
  101.      * Now draw the sphere object scaled down. We use the pushmatrix
  102.      * and the popmatrix to preserve the transformation matrix so
  103.      * that only this sphere is drawn scaled.
  104.      */
  105.     color(CYAN);
  106.  
  107.     ortho2(0.0, 1.0, 0.0, 1.0);
  108.     hcentertext(1);
  109.     htextsize(0.08, 0.15);
  110.     move2(0.6, 0.3);
  111.     htextang(-90.0);
  112.     hcharstr("1st rule...");
  113.     
  114.     pushmatrix();
  115.         scale(0.5, 0.5, 0.5);
  116.         callobj(SPHERE);
  117.     popmatrix();
  118.  
  119.     /*
  120.      * now we draw the same sphere translated, with a different
  121.      * scale and color.
  122.      */
  123.  
  124.     color(WHITE);
  125.  
  126.     pushmatrix();
  127.         translate(0.0, -1.4 * RADIUS, 1.4 * RADIUS);
  128.         scale(0.7, 0.4, 0.3);
  129.         callobj(SPHERE);
  130.     popmatrix();
  131.  
  132.     /*
  133.      * and maybe a few more times....
  134.      */
  135.  
  136.     color(RED);
  137.  
  138.     pushmatrix();
  139.         translate(0.0, RADIUS, 0.7 * RADIUS);
  140.         scale(0.2, 0.2, 0.2);
  141.         callobj(SPHERE);
  142.     popmatrix();
  143.  
  144.     color(GREEN);
  145.  
  146.     pushmatrix();
  147.         translate(0.0, 1.5 * RADIUS, -RADIUS);
  148.         scale(0.15, 0.15, 0.15);
  149.         callobj(SPHERE);
  150.     popmatrix();
  151.  
  152.     color(YELLOW);
  153.  
  154.     pushmatrix();
  155.         translate(0.0, -RADIUS, -RADIUS);
  156.         scale(0.12, 0.12, 0.12);
  157.         callobj(SPHERE);
  158.     popmatrix();
  159.  
  160.     color(BLUE);
  161.  
  162.     pushmatrix();
  163.         translate(0.0, -2.0*RADIUS, -RADIUS);
  164.         scale(0.3, 0.3, 0.3);
  165.         callobj(SPHERE);
  166.     popmatrix();
  167.  
  168.     ortho2(0.0, 1.0, 0.0, 1.0);
  169.     hcentertext(1);
  170.     htextsize(0.08, 0.15);
  171.     move2(0.8, 0.5);
  172.     htextang(-90.0);
  173.     hcharstr("I'm very ordinary!");
  174.     move2(0.8, 0.5);
  175.     htextang(-37.0);
  176.     hcharstr("I'm a fucking dude!");
  177.  
  178.     qread(&val);
  179.  
  180.     gexit();
  181. }
  182.